package com.example.studyplanning.mapper;

import com.example.studyplanning.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //查询所有用户信息
    @Select("select * from user")
    List<User> FindAllUser();

    //5.1展示用户名称
    @Select("select userID,userName from user where userID=#{userID}")
    List<User> getUser(Integer userID);

    //1.6举报用户，根据所举报的用户获得用户ID进行举报，次数达到三十次拉黑该用户
    @Update("update user set dislike=dislike+1 where userID=#{userID}")
    Integer UpdateUserDislike(Integer userID);

    //撤销举报
    @Update("update user set dislike=dislike-1 where userID=#{userID}")
    Integer UpdateDislike(Integer userID);

    //（后台） 1.1用户查询，根据用户名称和ID得到用户相关信息
    @Select("select userID,userName,userType,dislike from user where userName like '%${userName}%' and userID=#{userID}")
    List<User> FindUserByName(@Param("userName") String userName,@Param("userID") Integer userID);
    //辅助1.1用户查询
    @Select("select userID,userName,userType,dislike from user where userName like '%${userName}%'")
    List<User> findUserByName(String userName);

    //（后台）1.2用户删除,根据输入用户ID删除用户
    @Delete("delete from user where userID=#{userID}")
    Integer DelByID(Integer userID);

    //(后台）拉黑用户
    @Update("update user set userType=true where userID=#{userID}")
    Integer UpdateUserType(Integer userID);

    //(后台）1.3 拉黑用户的选择语句 查找所有被拉黑的用户
    @Select("select userID,userName,userType from user where userType=true")
    List<User> FindUser();

    //(后台）1.4解除用户
    @Update("update user set userType=false where userID=#{userID}")
    Integer updateUserType(Integer userID);

    //查询每日用户总数
    @Select("select createDate,sum(count(*)) over(order by createDate) as usersum from user group by createDate")
    List<User> findAlluser();
    //查询每日活跃用户数量
    @Select("SELECT count(DISTINCT task.userID) as activeuser,DATE_FORMAT(taskDate,'%Y-%m-%d') as active_time from user join task on task.userID=user.userID GROUP BY DATE_FORMAT(taskDate,'%Y-%m-%d')")
    List<User> findAllActiveuser();


}
